<?php

namespace pmvc\mvc\controller;

use pmvc\ioc\ObjectFactory;
use pmvc\ioc\InitializingObject;
use pmvc\mvc\ControllerMapping;
use pmvc\mvc\Controller;
use pmvc\util\StringUtil;
use Exception;

class RegexControllerMapping 
	implements InitializingObject,
	ControllerMapping {
		
	public $regexMap;

	private $objectFactory;

	public function initialize(ObjectFactory $objectFactory) {
		$this->objectFactory = $objectFactory;
	}

	public function getController($url) {
		foreach ($this->regexMap as $key => $val) {
			if (StringUtil::matches($key, $url, FALSE)) {
				return (is_string($val))
					? $this->objectFactory->getObjectById($val)
					: $val;
			}
		}
	}
}


?>